package com.example.fms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.fms.dto.req.NoticeReq;
import com.example.fms.dto.resp.NoticeResp;
import com.example.fms.entity.MinOrderRule;
import com.example.fms.entity.Notice;
import com.example.fms.mapper.MinOrderRuleMapper;
import com.example.fms.mapper.NoticeMapper;
import com.example.fms.service.MinOrderRuleService;
import com.example.fms.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Resource
    NoticeMapper noticeMapper;
    @Override
    public NoticeResp getNotice() {
        Notice notice = noticeMapper.selectOne(null);
        if (notice != null) {
            NoticeResp noticeResp = new NoticeResp();
            noticeResp.setId(notice.getId());
            noticeResp.setContent(notice.getContent());
            return noticeResp;
        }
        return null;
    }

    @Override
    public Boolean update(NoticeReq req) {
        Notice notice = noticeMapper.selectById(req.getId());
        if (notice != null) {
            notice.setContent(req.getContent());
            noticeMapper.updateById(notice);
            return true;
        }
        return null;
    }
}
